﻿using System;

class SpiralArray
{
    static void Main()
    {
        Console.Write("Enter a N: ");
        int n = int.Parse(Console.ReadLine());
        int[,] spiralMatrix = new int[n, n];
        int count = 1;
        int rowIndex = 0;
        int colIndex = 0;
        int maxRowIndex = n - 1;
        int maxColIndex = n - 1;
        do
        {
            for (int i = colIndex; i <= maxColIndex; i++)
            {
                spiralMatrix[rowIndex, i] = count;
                count++;
            }
            rowIndex++;
            for (int i = rowIndex; i <= maxRowIndex; i++)
            {
                spiralMatrix[i, maxColIndex] = count;
                count++;
            }
            maxColIndex--;
            for (int i = maxColIndex; i >= colIndex; i--)
            {
                spiralMatrix[maxRowIndex, i] = count;
                count++;
            }
            maxRowIndex--;
            for (int i = maxRowIndex; i >=rowIndex; i--)
            {
                spiralMatrix[i, colIndex] = count;
                count++;
            }
            colIndex++;
        }
        while (count <= n * n);
        {
            for (int rows = 0; rows < spiralMatrix.GetLength(0); rows++)
            {
                for (int cols = 0; cols < spiralMatrix.GetLength(1); cols++)
                {
                    Console.Write("{0,3}", spiralMatrix[rows,cols]);
                }
                Console.WriteLine();
            }

        }

           
    }
}